<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">会员登陆</view>
			<input class="u-border-bottom"  v-model="email" placeholder="邮箱" />
			<input class="u-border-bottom" type="password" v-model="password" placeholder="密码" />

			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">登陆</button>
			<view class="alternative">
				<view class="password" @click="toRegister">用户注册</view>
				<view class="issue" @click="toHome">返回首页</view>
			</view>
		</view>

		<view class="u-m-t-30 u-p-40">
			<u-table>
				<u-tr class="u-tr">
					<u-th class="u-th">邮箱</u-th>
					<u-th class="u-th">密码</u-th>
				</u-tr>
				<u-tr class="u-tr">
					<u-td class="u-td">jk006@qq.com</u-td>
					<u-td class="u-td">qqq111</u-td>
				</u-tr>
			</u-table>
		</view>
		
      <tab-bar></tab-bar>
	</view>
</template>

<script>
export default {
	data() {
		return {
			email: '',
			password:''
		}
	},
	computed: {
		inputStyle() {
			let style = {};
			if(this.$u.test.email(this.email) && this.password) {
				style.color = "#fff";
				style.backgroundColor = this.$u.color['warning'];
			}
			return style;
		}
	},
	// async onLoad() {
	// 	const userinfo = await this.$u.api.userinfo()
	// 	console.log(userinfo)
	// },
	methods: {
		async submit() {
			if(!this.$u.test.email(this.email) || !this.password) return
			// console.log(this.password)
			//登陆用的参数
			const params = {
				email:this.email,
				password:this.password
			}
			//登陆接口AIP数据

			const loginres = await this.$u.api.authLogin(params)
			
			//缓存 token
			this.$u.vuex('vuex_token',loginres.access_token)
			this.$u.toast('登陆成功')
			
			//utils 自定义工具 请求并缓存用户信息
			this.$u.utils.updateUser()
			
			//登陆后 跳转 到来源页
			const back_url = uni.getStorageSync('back_url') || 'pages/index/index'
			// console.log(back_url)
			setTimeout(()=>{
				this.$u.route({
					type:'reLaunch',    //reLaunch 可以跳转普通页和tabbar
					url:back_url
				})
			},1000)
			

		},
		toRegister(){
			this.$u.route({
				type:'redirect', 
				url:'pages/auth/register'
			})
		},
		toHome(){
			this.$u.route({
				type:'switchTab', 
				url:'pages/index/index'
			})
		},
		//page.josn自定义图标跳转
		onNavigationBarButtonTap(e) {
			console.log(e)
		    this.$u.route({
		    	type:'switchTab', 
		    	url:'pages/index/index'
		    })
		},

	}
};
</script>

<style lang="scss" scoped>
.u-border-bottom {
	margin-top: 40rpx !important;
}	
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;

		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-type-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		.getCaptcha {
			background-color: rgb(253, 243, 208);
			color: $u-tips-color;
			border: none;
			font-size: 30rpx;
			padding: 12rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}

}
</style>
